//
//  RecordController.m
//  
//
//  Created by l wb on 2018/5/22.
//

#import "RecordController.h"
#import "RecordCell.h"
@interface RecordController ()<UITableViewDataSource,UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic ,strong) NSArray *dataArr;
@end

@implementation RecordController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.title = @"追号记录";
    
    
    
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self getDataFromNet];

}
-(void)getDataFromNet{
    [CollectionNumberManager getCollectionNumberDataWithCompleteHandle:^(NSArray *arr) {
        NSLog(@"%@",arr);
        self.dataArr = arr;
        [self.tableView reloadData];
    }];
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    CollectionNumberModel *model = self.dataArr[indexPath.row];
    RecordCell *cell = [tableView dequeueReusableCellWithIdentifier:@"RecordCell"];
    cell.logoImg.image =[UIImage imageNamed:model.logoName];
    cell.typeLab.text = model.type;
    cell.dateLab.text = model.date;
//    [cell setWinNumWith:model.number];
    cell.numberLab.text = model.number;
    
    
    
    cell.deleteBtn.tag = indexPath.row;
    [cell.deleteBtn addTarget:self action:@selector(deleteNumberRecord:) forControlEvents:UIControlEventTouchUpInside];
    return cell;
}
-(void)deleteNumberRecord:(UIButton *)btn{
    CollectionNumberModel *model =  self.dataArr[btn.tag];
    BmobObject *object = [BmobObject objectWithoutDataWithClassName:@"NumberRecord" objectId:model.objectID];
    [object deleteInBackgroundWithBlock:^(BOOL isSuccessful, NSError *error) {
        if (isSuccessful) {
            [EasyTextView showText:@"删除成功"];
            [self getDataFromNet];
        }else{
            NSLog(@"error--%@",error);
        }
        
    }];
    
}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArr.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 90;
}

@end
